﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JiaBao.Core.Domain;

namespace JiaBao.Data
{
    public interface IDbContext
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        IDbSet<TEntity> Set<TEntity>() where TEntity:BaseEntity;
 
        /// <summary>
        /// 保存更改
        /// </summary>
        /// <returns></returns>
        int SaveChanges();

        /// <summary>
        /// 执行存储过程并返回实体结果
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="commandText"></param>
        /// <param name="paraeters"></param>
        /// <returns></returns>
        IList<TEntity> ExecuteStoredProcedureList<TEntity>(string commandText, params object[] paraeters) where TEntity : BaseEntity, new();

        /// <summary>
        /// 执行原始sql语句 返回指定泛型结果集
        /// </summary>
        /// <typeparam name="TElement"></typeparam>
        /// <param name="sql"></param>
        /// <param name="paramenters"></param>
        /// <returns></returns>
        IEnumerable<TElement> SqlQuery<TElement>(string sql, params object[] paramenters);


        /// <summary>
        /// 执行sql语句 返回受影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="doNotEnsureTransaction"></param>
        /// <param name="timeout"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        int ExecuteSqlCommand(string sql, bool doNotEnsureTransaction, int? timeout = null, params object[] parameters);

        /// <summary>
        /// 分离实体
        /// </summary>
        /// <param name="entity"></param>
        void Detach(object entity);


        /// <summary>
        /// 是否代理创建
        /// </summary>
        bool ProxyCreationEnabled { get; set; }

        /// <summary>
        /// 是否自动检测更改
        /// </summary>
        bool AutoDetectChangesEnabled { get; set; }

    }
}
